package com.htudata.core.util.operation;

import java.math.BigDecimal;

public class MathOperationUtils {

  
  public static String round(String val, int decimalPlace) {
    return round(val, decimalPlace, 4);
  }
  
  public static String round(String val, int decimalPlace, int roundType) {
    if (!StringOperationUtils.isValidStr2(val))
      return val; 
    if (!StringOperationUtils.isNumeric(val))
      return val; 
    String result = (new BigDecimal(val)).setScale(decimalPlace, roundType) + "";
    return result;
  }
  
  public static Double getNearestMultiple(double num1, double num2) {
    if (!StringOperationUtils.isNumeric(num1 + ""))
      return Double.valueOf(-1.0D); 
    if (!StringOperationUtils.isNumeric(num2 + ""))
      return Double.valueOf(-1.0D); 
    double n = Math.floor(num1 / num2);
    if (n == 0.0D)
      return Double.valueOf(0.0D); 
    double result = n * num2;
    return Double.valueOf(result);
  }
}
